//
//  AfterSaleViewController.m
//  AnXin100
//
//  Created by Sakura on 2018/11/5.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AfterSaleViewController.h"
#import "AfterSaleTableViewCell.h"
@interface AfterSaleViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIView *headView;

@property (nonatomic, strong) UITableView *mainTable;

@property (nonatomic, strong) UIImageView *productImage;

@property (nonatomic, strong) UILabel *productNameLabel;

@property (nonatomic, strong) UILabel *priceLabel;

@property (nonatomic, strong) NSArray *array;

@property (nonatomic, strong) UIView *footView;

@end

@implementation AfterSaleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _array = @[@{@"name" : @"仅退款",
                 @"detail" : @"未收到货（包含未签收），或卖家协商同意前提下",
                 @"icon" : @"refundMoney"},
               @{@"name" : @"退货退款",
                 @"detail" : @"已收到货，需要退换已收到的货物",
                 @"icon" : @"refundGoods"},
               @{@"name" : @"换货",
                 @"detail" : @"商品存在质量问题，联系卖家协商换货",
                 @"icon" : @"exchangeGoods"}];
    [self.view addSubview:self.mainTable];
}

- (UITableView *)mainTable {
    if (!_mainTable) {
        _mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, Hn, SCREEN_WIDTH, SCREEN_HEIGHT - Hn) style:UITableViewStylePlain];
        _mainTable.tableHeaderView = self.headView;
        _mainTable.tableFooterView = self.footView;
        _mainTable.delegate = self;
        _mainTable.dataSource = self;
        _mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_mainTable registerClass:[AfterSaleTableViewCell class] forCellReuseIdentifier:@"AfterSaleTableViewCell"];
    }
    return _mainTable;
}

- (UIView *)headView {
    if (!_headView) {
        _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 95)];
        _headView.backgroundColor = [UIColor whiteColor];
        
        _productImage = [[UIImageView alloc] init];
        _productImage.image = [UIImage imageNamed:@"grape"];
        [_headView addSubview:_productImage];
        
        _productImage.sd_layout
        .leftSpaceToView(_headView, 10)
        .topSpaceToView(_headView, 10)
        .bottomSpaceToView(_headView, 20)
        .widthIs(114);
        [_headView layoutIfNeeded];
        
        _productNameLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:FONT_SIXTEEN rect:CGRectNull];
        [_headView addSubview:_productNameLabel];
        _productNameLabel.text = @"新鲜夏季酸草莓水果1000g 烘焙蛋糕装饰冰饮专用";
        _productNameLabel.numberOfLines = 2;
        _productNameLabel.sd_layout
        .leftSpaceToView(_productImage, 10)
        .topEqualToView(_productImage)
        .rightSpaceToView(_headView, 10)
        .heightIs(50);
        
        _priceLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x666666] font:[UIFont systemFontOfSize:14] rect:CGRectNull];
        _priceLabel.text = @"共一件商品 合计：98.00（含运费¥0.00）";
        [_headView addSubview:_priceLabel];
        
        _priceLabel.sd_layout
        .leftEqualToView(_productNameLabel)
        .rightEqualToView(_productNameLabel)
        .bottomEqualToView(_productImage)
        .heightIs(15);
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 85, SCREEN_WIDTH, 10)];
        lineView.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
        [_headView addSubview:lineView];
        
    }
    return _headView;
}

- (UIView *)footView {
    if (!_footView) {
        _footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
        _footView.backgroundColor = [UIColor whiteColor];
        UILabel *titleLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:[UIFont systemFontOfSize:14] rect:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
        titleLabel.text = @"申请原因";
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [_footView addSubview:titleLabel];
        
        NSArray *array = @[@"质保期外问题", @"商品故障", @"其他"];
        for (NSInteger i = 0; i < array.count; i++) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 40 * (i + 1), SCREEN_WIDTH, 40)];
            UILabel *titleLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:[UIFont systemFontOfSize:14] rect:CGRectMake(10, 0, 120, 40)];
            titleLabel.text = array[i];
            [view addSubview:titleLabel];
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(SCREEN_WIDTH - 30, 15, 20, 20);
            [button setImage:[UIImage imageNamed:@"roundSelec"] forState:UIControlStateNormal];
            [view addSubview:button];
            [_footView addSubview:view];
        }
        
    }
    return _footView;
}


#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AfterSaleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AfterSaleTableViewCell"];
    cell.dic = _array[indexPath.row];
    return cell;
}


@end
